package com.taptech.doufu.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.taptech.doufu.constant.UserDetailCardType
import com.taptech.doufu.model.user.ListItem
import com.taptech.doufu.ui.view.userdetail.*

class UserDetailAdapter(context: Context, val uid:Int, private val readRecordStatus:Int):BaseRecyclerAdappter<ListItem,UserDetailAdapter.ViewHolder>(context) {



    override fun getItemViewType(position: Int): Int {
        if (dataList.size > position) {
            return dataList[position].type
        }
        return super.getItemViewType(position)
    }


    fun getItem(position: Int): ListItem {
        if (dataList.size > position) {
            return dataList[position]
        }
        return ListItem()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        when (viewType) {
            UserDetailCardType.SUM_INFO -> {
                val view = UserDetailSumInfoView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.LATEST_NOVEL -> {
                val view = UserDetailLatestNovelView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.NOVEL_LIST -> {
                val view = UserDetailNovelListView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.SINGLE_PAGE_NOVEL_LIST->{
                val view = UserDetailStoryListView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.FANS_LIST -> {
                val view = UserDetailFansRankView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.MEDALS_LIST -> {
                val view = UserDetailMedalView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.FANS_SUM -> {
                val view = UserDetailFansSumView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.LATEST_READ -> {
                val view = UserDetailLatestReadView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.LATEST_READ_EMPTY -> {
                val view = UserDetailLatestReadView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.LATEST_ACTIVITIES -> {
                val view = UserDetailActivityView(mContext)
                return ViewHolder(view)
            }
            UserDetailCardType.LATEST_ACTIVITY_EMPTY -> {
                val view = UserDetailActivityView(mContext)
                return ViewHolder(view)
            }

            UserDetailCardType.LATEST_REVIEW -> {
                val view = UserDetailReviewView(mContext)
                return ViewHolder(view)
            }

            UserDetailCardType.LATEST_REVIEW_EMPTY -> {
                val view = UserDetailReviewView(mContext)
                return ViewHolder(view)
            }

            UserDetailCardType.LATEST_JOURNAL->{
                val view = UserDetailJournalView(mContext)
                return ViewHolder(view)
            }

            UserDetailCardType.LATEST_JOURNAL_EMPTY->{
                val view = UserDetailJournalView(mContext)
                return ViewHolder(view)
            }
            else -> {
                val view = View(mContext)
                return ViewHolder(view)
            }
        }
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val item = getItem(position)
        when (item.type) {
            UserDetailCardType.SUM_INFO -> {
                val view = holder.itemView as UserDetailSumInfoView
                view.setData(uid,item)
            }
            UserDetailCardType.LATEST_NOVEL -> {
                val view = holder.itemView as UserDetailLatestNovelView
                view.setData(item)
            }
            UserDetailCardType.NOVEL_LIST -> {
                val view = holder.itemView as UserDetailNovelListView
                view.setData(uid,item)
            }

            UserDetailCardType.SINGLE_PAGE_NOVEL_LIST -> {
                val view = holder.itemView as UserDetailStoryListView
                view.setData(uid,item)
            }
            UserDetailCardType.FANS_LIST -> {
                val view = holder.itemView as UserDetailFansRankView
                view.setData(uid,item)
            }
            UserDetailCardType.MEDALS_LIST -> {
                val view = holder.itemView as UserDetailMedalView
                view.setData(uid,item)
            }
            UserDetailCardType.FANS_SUM -> {
                val view = holder.itemView as UserDetailFansSumView
                view.setData(uid,item)
            }
            UserDetailCardType.LATEST_READ -> {
                val view = holder.itemView as UserDetailLatestReadView
                view.setData(uid,readRecordStatus,item)
            }
            UserDetailCardType.LATEST_READ_EMPTY -> {
                val view = holder.itemView as UserDetailLatestReadView
                view.setContentNullData(uid,readRecordStatus)
            }
            UserDetailCardType.LATEST_ACTIVITIES -> {
                val view = holder.itemView as UserDetailActivityView
                view.setData(uid,item)
            }

            UserDetailCardType.LATEST_ACTIVITY_EMPTY -> {
                val view = holder.itemView as UserDetailActivityView
                view.setContentNullData()
            }
            UserDetailCardType.LATEST_REVIEW -> {
                val view = holder.itemView as UserDetailReviewView
                view.setData(uid,item)
            }
            UserDetailCardType.LATEST_REVIEW_EMPTY -> {
                val view = holder.itemView as UserDetailReviewView
                view.setContentNullData()
            }
            UserDetailCardType.LATEST_JOURNAL -> {
                val view = holder.itemView as UserDetailJournalView
                view.setData(uid,item)
            }
            UserDetailCardType.LATEST_JOURNAL_EMPTY -> {
                val view = holder.itemView as UserDetailJournalView
                view.setContentNullData()
            }
            else -> {

            }
        }
    }


    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}